package com.eagletsoft.mmproj.ui;

import java.util.List;
import java.util.Random;

import com.eagletsoft.mmproj.R;
import com.eagletsoft.mmproj.model.MessageModel;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class PageLayoutView extends FrameLayout  {
	
	public final static Integer[] LAYOUT_IDS = new Integer[] { R.layout.page_layout_1,
		R.layout.page_layout_2, R.layout.page_layout_3,R.layout.page_layout_4,R.layout.page_layout_5 };
	
	private LinearLayout view1;
	private LinearLayout view2;
	private LinearLayout view3;
	private LinearLayout view4;
	private LinearLayout view5;
	private int layoutIndex;

	public PageLayoutView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initalizeViews();
	}
	
	public void initalizeViews(){
		layoutIndex = new Random().nextInt(5);
		LayoutInflater inflater = LayoutInflater.from(getContext());  
		View layoutView = inflater.inflate(LAYOUT_IDS[layoutIndex], null);
         
        view1 = (LinearLayout)layoutView.findViewById(R.id.view1);
        view2 = (LinearLayout)layoutView.findViewById(R.id.view2);
        view3 = (LinearLayout)layoutView.findViewById(R.id.view3);
        view4 = (LinearLayout)layoutView.findViewById(R.id.view4);
        view5 = (LinearLayout)layoutView.findViewById(R.id.view5);
        
        addView(layoutView);
	}
	
	public void setData(List<MessageModel> data) {
		for(int i = 0; i < data.size(); i++){
			TitleAndImageView view = new TitleAndImageView(this.getContext());
			view.setTitle(data.get(i).messageTitle);
			view.setImage(data.get(i).messageImage);
			LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
			if (i == 0) {
				view1.addView(view,lp);
			}
			if (i == 1) {
				view2.addView(view,lp);
			}
			if (i == 2) {
				view3.addView(view,lp);
			}
			if (i == 3) {
				view4.addView(view,lp);
			}
			if (i == 4) {
				view5.addView(view,lp);
			}
		}
	}

	public int getLayoutIndex() {
		return layoutIndex;
	}

	
}
